let num = 0;
var index = 0;
function next_pic(){
  let wrap = document.querySelector(".wrap");
  if(num == 3){
    wrap.style.left = "-530px";
    num = -1;
    wrap.style.transition = "0s";
  }else{
      let newLeft = parseInt(wrap.style.left)-750;
      wrap.style.left = newLeft+"px";
			wrap.style.transition = "0.7s";
  }
  num++;

  //如果切换下一张图片时设置计数的变量index自增，如果到最后一张图片则让index等于0
  index++;
  if(index >= 4){
    index = 0;
  }
  showCurrentDot();
}
function prev_pic(){
  let wrap = document.querySelector(".wrap");
  if(num == 0){
    wrap.style.left = "-3550px";
    num = 4;
  }
  let newLeft = parseInt(wrap.style.left)+750;
  wrap.style.left = newLeft+"px";
  num--;

  index--;
  if(index <= 0){
      index = 4;
  }
  showCurrentDot();

}
//如果切换下一张图片时更换span小圆点的背景色
var dots = document.getElementsByTagName("span");
  function showCurrentDot () {
    for(var i = 0;i < 4; i++){
      dots[i].className = "";
    }
    dots[index].className = "on";
  }

let timer = setInterval(()=>{
  next_pic();
},1300);

function stop(){
  clearInterval(timer);
}
function start(){
  timer = setInterval(()=>{
    next_pic();
  },1300);
}